class Score{
	constructor() {
	    this.num = 0;
		this.lv =[2,4,80,160,320,640,1280,2560,5120]
	}
	setVal(){
		this.num+=1;
	}
	set history(val){
		// 如果历史最高分数小于当前值，设置当前值为最高分
		if(+this.history<val){
			localStorage.setItem('snakeHistroy',val)
		}
	}
	get history(){
		return localStorage.getItem('snakeHistroy') || 0
	}
	get level(){
		var lv = this.lv
		var len = lv.length;
		var num = this.num;
		for (let i = 0; i < len; i++) {
			if(lv[i]>=num){
				return i;
			}
		}
	}
	
	clear(){
		this.num=0;
	}
	getVal(){
		return this.num;
	}
	getFormat(val){
		let temp = ''
		let prefix ='0';
		let len = (val+'').length;
		if(len<4){
			temp = prefix.repeat(4-len) + val
		}
		return temp
	}
}